package com.lxmes.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.business.domain.CcPlanItemGet;
import com.lxmes.business.service.ICcPlanItemGetService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 物料领用计划Controller
 * 
 * @author 张志煜
 * @date 2023-01-15
 */
@RestController
@RequestMapping("/business/planItemGet")
public class CcPlanItemGetController extends BaseController
{
    @Autowired
    private ICcPlanItemGetService ccPlanItemGetService;

    /**
     * 查询物料领用计划列表
     */
    @PreAuthorize("@ss.hasPermi('business:planItemGet:list')")
    @GetMapping("/list")
    public TableDataInfo list(CcPlanItemGet ccPlanItemGet)
    {
        startPage();
        List<CcPlanItemGet> list = ccPlanItemGetService.selectCcPlanItemGetList(ccPlanItemGet);
        return getDataTable(list);
    }

    /**
     * 导出物料领用计划列表
     */
    @PreAuthorize("@ss.hasPermi('business:planItemGet:export')")
    @Log(title = "物料领用计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CcPlanItemGet ccPlanItemGet)
    {
        List<CcPlanItemGet> list = ccPlanItemGetService.selectCcPlanItemGetList(ccPlanItemGet);
        ExcelUtil<CcPlanItemGet> util = new ExcelUtil<CcPlanItemGet>(CcPlanItemGet.class);
        util.exportExcel(response, list, "物料领用计划数据");
    }

    /**
     * 获取物料领用计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:planItemGet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ccPlanItemGetService.selectCcPlanItemGetById(id));
    }
    /*生成出库单*/
    @Log(title = "生成出库单", businessType = BusinessType.GENCODE)
    @GetMapping("addScChuKu/{ids}")
    public AjaxResult addScChuKu(@PathVariable Long[] ids)
    {
        return toAjax(ccPlanItemGetService.addScChuKu(ids));
    }


    /**
     * 新增物料领用计划
     */
    @PreAuthorize("@ss.hasPermi('business:planItemGet:add')")
    @Log(title = "物料领用计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CcPlanItemGet ccPlanItemGet)
    {
        return toAjax(ccPlanItemGetService.insertCcPlanItemGet(ccPlanItemGet));
    }

    /**
     * 修改物料领用计划
     */
    @PreAuthorize("@ss.hasPermi('business:planItemGet:edit')")
    @Log(title = "物料领用计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CcPlanItemGet ccPlanItemGet)
    {
        return toAjax(ccPlanItemGetService.updateCcPlanItemGet(ccPlanItemGet));
    }

    /**
     * 删除物料领用计划
     */
    @PreAuthorize("@ss.hasPermi('business:planItemGet:remove')")
    @Log(title = "物料领用计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ccPlanItemGetService.deleteCcPlanItemGetByIds(ids));
    }
}
